package com.czh.seckill.utils;

import org.springframework.stereotype.Component;
import org.apache.commons.codec.digest.DigestUtils;


@Component
public class MD5Utils {
    public static String md5(String str) {
        return DigestUtils.md5Hex(str);
    }

    private static final String salt = "1a2b3c4d";

    public static String inputPassToFromPass(String inputPass) {
        String ss = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        return md5(ss);
    }

    public static String fromPassToDBPass(String fromPass, String salt) {
        String ss = "" + salt.charAt(0) + salt.charAt(2) + fromPass + salt.charAt(5) + salt.charAt(4);
        return md5(ss);
    }

    public static String inputPassToDBPass(String inputPass, String salt) {
        String fromPass = inputPassToFromPass(inputPass);
        return fromPassToDBPass(fromPass, salt);
    }

    public static void main(String[] args) {
        String inputPass = "123456";
        String fromPass = inputPassToFromPass(inputPass);
        System.out.println(fromPass);
        System.out.println(fromPassToDBPass(fromPass, "1a2b3c4d"));
        System.out.println(inputPassToDBPass(inputPass, "1a2b3c4d"));
    }
}
